package DBHandle;

import java.sql.*;
import java.util.*;

public class General
{
	DBConn.DBConnManager db=new DBConn.DBConnManager();
	ResultSet rs=null;
	Statement stmt=null;
	String sql="";	
	Connection conn=db.getConnection("Mysql");
	
	
	//获取列表（无参数）
	public ArrayList<String> SelectArrayList(String content,String table) throws Exception
	{
		ArrayList<String> temp=new ArrayList<String>();
		if(conn!=null)
		{
			sql="select distinct "+content+" from "+table+" order by id";
			stmt=conn.createStatement();
			rs=stmt.executeQuery(sql);
			while(rs.next())
			{
				temp.add(rs.getString(1));
			}
			rs.close();
			stmt.close();
			db.releaseConnection("Mysql", conn);
		}
		return temp;
	}

	
	//根据唯一筛选条件 获取编号（返回int）
	public int SelectID(String table,String row,String value) throws Exception
	{
		int temp=0;
		if(conn!=null)
		{			
			sql="select id from "+table+" where "+row+" = '"+value+"'";
			stmt=conn.createStatement();
			rs=stmt.executeQuery(sql);
			while(rs.next())
				temp=rs.getInt(1);
			rs.close();
			stmt.close();
			db.releaseConnection("Mysql", conn);
		}
		return temp;
	}
	
	//根据唯一筛选条件 获取信息（返回String）
	public String SelectInfoString(String selectValue, String table,String row,String rowValue) throws Exception
	{
		String temp="";
		if(conn!=null)
		{			
			sql="select "+selectValue+" from "+table+" where "+row+" = '"+rowValue+"'";
			stmt=conn.createStatement();
			rs=stmt.executeQuery(sql);
			while(rs.next())
				temp=rs.getString(1);
			rs.close();
			stmt.close();
			db.releaseConnection("Mysql", conn);
		}
		return temp;
	}
	
	//根据唯一筛选条件 获取信息（返回int）
	public int SelectInfoInt(String selectValue, String table,String row,String rowValue) throws Exception
	{
		int temp=0;
		if(conn!=null)
		{			
			sql="select "+selectValue+" from "+table+" where "+row+" = '"+rowValue+"'";
			stmt=conn.createStatement();
			rs=stmt.executeQuery(sql);
			while(rs.next())
				temp=rs.getInt(1);
			rs.close();
			stmt.close();
			db.releaseConnection("Mysql", conn);
		}
		return temp;
	}
}